// $Id: jpeg.h 96 2011-10-20 16:24:38Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef JPEG_H_
#define JPEG_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>
#include <sys/time.h>
#include <event.h>
#include <niortsp/jpeg.h>

#include "rtp.h"
#include "rtsp.h"
#include "transport.h"

struct timeval;

struct zcbuffer;

struct niortp_jpeg_size {
	unsigned int width;
	unsigned int height;
};

struct niortp_jpeg {
	struct event_base *evbase;
	int setup;
	int fd;
	struct niortp_transport_param param;
	struct event ev;
	struct timeval tv;
	u_int32_t sequence;
	struct niortp_transport_stat old;
	struct niortp_transport_stat new;
	struct zcqueue *queue;
	struct zcqueue *dropping;
	size_t offset;
	struct timeval previous;
	struct timeval timestamp;
	struct zcbuffer *buffer;
	struct timeval start;
	struct {
		struct niortsp_interleaved_header interleaved;
		struct niortp_header rtp;
		struct niortp_jpeg_header jpeg;
		struct niortp_jpeg_qtable qtable;
	} header;
	struct niortp_jpeg_size size;
	struct niortp_slice *qtables;
	unsigned int max_qtables;
	unsigned int num_qtables;
	u_int16_t size_qtables;
	struct {
		struct {
			size_t len;
			size_t written;
		} header;
		struct {
			unsigned int index;
			size_t written;
		} qtable;
		size_t len;
		size_t written;
	} packet;
};

void *niortp_jpeg_create(struct event_base *evbase);

void niortp_jpeg_destroy(void *priv);

int niortp_jpeg_setup(void *obj, int fd, struct niortp_transport_param *param);

int niortp_jpeg_teardown(void *obj);

int niortp_jpeg_send(void *obj, const struct timeval *timestamp,
		struct zcbuffer *frame);

int niortp_jpeg_pending(void *obj);

int niortp_jpeg_next(void *obj);

int niortp_jpeg_stat(void *obj, struct niortp_transport_stat *stat);

#ifdef __cplusplus
}
#endif

#endif /* JPEG_H_ */
